import tkinter as tk
from tkinter import messagebox
 
def login():
    username = username_entry.get()
    password = password_entry.get()
    
    # 假设的用户名和密码
    correct_username = "user"
    correct_password = "pass"
    
    if username == correct_username and password == correct_password:
        # 登录成功，关闭登录窗口并打开主界面
        login_window.destroy()
        main_window(username,'design')
    else:
        # 登录失败，显示错误消息
        messagebox.showerror("登录失败", "用户名或密码错误")
 
def main_window(username,role):
    main = tk.Tk()
    main.title(username+role+"主界面")
    main.geometry("400x300")
    tk.Label(main, text="欢迎进入主界面").pack(pady=20)
    main.mainloop()
 
# 创建登录窗口
login_window = tk.Tk()
login_window.title("登录界面")
login_window.geometry("300x200")
 
# 创建用户名和密码输入框
tk.Label(login_window, text="用户名:").pack()
username_entry = tk.Entry(login_window)
username_entry.pack()
tk.Label(login_window, text="密码:").pack()
password_entry = tk.Entry(login_window, show="*")  # 显示星号代替密码字符
password_entry.pack()
 
# 创建登录按钮并绑定登录函数
login_button = tk.Button(login_window, text="登录", command=login)
login_button.pack(pady=20)
 
login_window.mainloop()